<?php

namespace App\Clients;

use GuzzleHttp\Client;

class BaseClient
{

    /**
     * Request Client.
     * @var Client;
     */
    public static $client;

    /**
     * 获取Request Client
     * @param array $headers
     * @return Client
     */
    public static function getClient($headers = []): Client
    {
        if (!static::$client) {
            $headers = array_merge([
                'Content-Type' => 'application/json',
            ], $headers);

            static::$client = new Client([
                'timeout' => 0,

                'defaults' => [
                    'verify' => false,
                    'http_errors' => false,
                ],
                'headers' => $headers,
            ]);

        }

        return static::$client;
    }

    public static function get($uri, $data)
    {
        $client = static::getClient();
        return $client->get($uri, $data);
    }

    public static function post($uri, $data)
    {
        $client = static::getClient();
        return $client->post($uri, $data);
    }
}
